﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yu.Cms.Config;
using Yu.Cms.Common;

namespace Yu.Cms.Web.UserCtrl.Admin
{
    public partial class SysConfig : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.OnStart();
            }
        }

        /// <summary>
        /// 初始化
        /// </summary>
        protected void OnStart()
        {
            SiteConfigInfo model = SiteConfig.GetConfig();
            txtName.Text = model.SiteName;
            txtUrl.Text = model.SiteUrl;
            txtKey.Text = model.SiteKeyWord;
            txtInfo.Text = model.SiteInfo;
            txtICP.Text = model.SiteICP;
            txtRigth.Text = model.SiteCopyright;
            txtEmail.Text = model.SiteEmail;
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            SiteConfigInfo model = SiteConfig.GetConfig();
            model.SiteName = YuRequest.GetFormString(txtName.UniqueID);
            model.SiteUrl = YuRequest.GetFormString(txtUrl.UniqueID);
            model.SiteKeyWord = YuRequest.GetFormString(txtKey.UniqueID);
            model.SiteInfo = YuRequest.GetFormString(txtInfo.UniqueID);
            model.SiteICP = YuRequest.GetFormString(txtICP.UniqueID);
            model.SiteCopyright = YuRequest.GetFormString(txtRigth.UniqueID);
            model.SiteEmail = YuRequest.GetFormString(txtEmail.UniqueID);
            this.UpdateConfigInfo(model);
        }

        /// <summary>
        /// 更新设置信息
        /// </summary>
        /// <param name="model"></param>
        protected void UpdateConfigInfo(SiteConfigInfo model)
        {
            if (model != null)
            {
                SiteConfig.Serialiaze(model, SiteConfigFileManager.ConfigFilePath);
            }
        }
    }
}